package com.daikuan.lizh.widget;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.daikuan.lizh.R;


/**
 * Created by jiming1 on 2016/8/9.
 */
public class ShareDialogFragment extends DialogFragment {

	private Dialog dialog;


	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {

		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.MyCustomDialog);
		LayoutInflater inflater = getActivity().getLayoutInflater();
		View view = inflater.inflate(R.layout.dialog_contan_us, null);
		initData();
		builder.setView(view);
		dialog = builder.create();
		// 设置宽度为屏宽、靠近屏幕底部。
		Window window = dialog.getWindow();
		WindowManager.LayoutParams wlp = window.getAttributes();
		wlp.width = WindowManager.LayoutParams.MATCH_PARENT;
		wlp.gravity = Gravity.CENTER;
		window.setAttributes(wlp);
		view.findViewById(R.id.tvClose).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dismiss();
			}
		});
		return dialog;
	}

	/**
	 * 初始化数据
	 */
	private void initData() {

	}


	@Override
	public void onStart() {
		super.onStart();
		DisplayMetrics dm = new DisplayMetrics();
		getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
		getDialog().getWindow().setLayout((int) (dm.widthPixels * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT);
	}

}
